precision mediump float;

uniform vec4 ambientColor;
uniform vec4 diffuseColor;
uniform vec4 specularColor;
uniform sampler2D colorMap;

varying vec3 vVaryingLightDir;
varying vec3 vVaryingNormal;
varying vec2 vTexCoords;

void main(){
	
	vec3 vNormal=normalize(vVaryingNormal);
	vec3 vLightDir=normalize(vVaryingLightDir);
	
	vec4 vFragColor = ambientColor;
	
	float diff = max(0.0 , dot(vNormal,vLightDir));
	vFragColor += diff*diffuseColor;
	
	vFragColor *= texture2D(colorMap,vTexCoords);
	
	vec3 vReflect = normalize(reflect( -vNormal, vLightDir));
	float spec= max(0.0 , dot( vNormal, vReflect));
	if(diff != 0.0){
		float fSpec=pow(spec,128.0);
		vFragColor.rgb+= vec3(fSpec,fSpec,fSpec);
	}
	
	gl_FragColor=vFragColor;
}